<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者，助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 2017～2024  www.wdadmin.cn    All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn>   www.wdadmin.cn
// +----------------------------------------------------------------------
/**
 * Class Driver
 * Desc  代驾Model
 * Create on 2024/10/26 17:11
 * Create by wangyafang
 */

namespace app\admin\model\wddj;


use think\Model;

class Trailer extends Model
{
// 表名
    protected $name = 'wddj_driver_trailer';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'base_info',
    ];

    public static function getBaseInfoAttr($value, $data)
    {
        $id = $data['id'];
        $driverObj = self::where('d.id',$id)
            ->alias('d')
            ->join('wddj_certified_driving_agent_trailer certified','d.wechat_id = certified.wechat_id')
            ->field('certified.name,d.wechat_id')
            ->find();

        $acceptance_number = (new \app\admin\model\wddj\trailer\Order())->where('state','in',['accepted','in_progress','adjusting','refunded','awaiting_payment','completed'])
            ->where('driver_id',$id)
            ->where('driver_wechat_id',$driverObj->wechat_id)
            ->count();
        $total_pay_amount = (new \app\admin\model\wddj\trailer\Order())->where('state','in',['accepted','in_progress','adjusting','refunded','awaiting_payment','completed'])
            ->where('driver_id',$id)
            ->where('driver_wechat_id',$driverObj->wechat_id)
            ->sum('actual_amount');
        return array(
            'name'=>$driverObj['name'],
            'acceptance_number'=>$acceptance_number,
            'total_pay_amount'=>$total_pay_amount.'元',
        );

    }
}



 